console.log("openai.js loaded");
var msgQueue=[];
chrome.runtime.sendMessage({type: "register", windowId: "openai"});
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
    console.log("douyin.js openaionMessage", message);
    if(document.querySelector("textarea").parentNode.lastChild.querySelector("svg")){
        document.querySelector("textarea").value=message.data
        document.querySelector("textarea").parentNode.lastChild.click();
    }else{
        msgQueue.push(message.data);
    }
    sendResponse({code: 200, msg: "收到消息"});
    setInterval(function () {
        if(msgQueue.length>0&&document.querySelector("textarea").parentNode.lastChild.querySelector("svg")){
            console.log("当前还有"+msgQueue.length+"条问题未回答");
            document.querySelector("textarea").value=msgQueue.shift();
            document.querySelector("textarea").parentNode.lastChild.click();
        }
    },1000)
})
